function [ out ] = sigmoid( x,type = 0)
  % sigmoid: Sigmoid函数
  %
  % x:入力值
  % type:
  %   0:普通
  %   1:求导S(x)(1-S(x))
  %   2:对数求导 dxln(sx) = dx(sx)/sx = (1-S(x))
  %   3:对数求导（反向） dxln(1-sx) = dx(1-sx)/(1-sx) = -S(x)
  %
  out = 1./(1+exp(-x));
  switch (type)
  case 1
    out = out.*(1-out);
  case 2
    out = 1-out;
  case 3
    out = -out;
  endswitch

end  % sigmoid
